package Transformers;

import org.joda.time.LocalDate;
import org.uqbar.arena.bindings.Transformer;

public class StringToLocalDateTransformer implements Transformer<LocalDate, String> {

	// @Override
	// public String viewToModel(LocalDate valueFromView) {
	// return valueFromView.dayOfWeek().getAsText() +
	// " / " + valueFromView.dayOfMonth().getAsText() +
	// " / " + valueFromView.dayOfYear().getAsText();
	// }
	//
	// @Override
	// public LocalDate modelToView(String valueFromModel) {
	// String s = valueFromModel.replaceAll(" ","");
	// return new LocalDate(Integer.parseInt(s.substring(0, 2)),
	// Integer.parseInt(s.substring(3, 5)),
	// Integer.parseInt(s.substring(6, 8)));
	// }

	@Override
	public LocalDate viewToModel(String valueFromView) {
		String s = valueFromView.replaceAll(" ", "");
		return new LocalDate(Integer.parseInt(s.substring(0, 4)),
		Integer.parseInt(s.substring(5, 7)), 
		Integer.parseInt(s.substring(8, 10)));
	}

	@Override
	public String modelToView(LocalDate valueFromModel) {
		return valueFromModel.dayOfWeek().getAsText() +
		" / " + valueFromModel.dayOfMonth().getAsText() +
		" / " + valueFromModel.dayOfYear().getAsText();
	}

	@Override
	public Class<LocalDate> getModelType() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Class<String> getViewType() {
		// TODO Auto-generated method stub
		return null;
	}

}
